package com.lxf.cn.rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.UUID;


/**
 * Created by liaoxuefeng on 2018/11/2.
 */

@Component
public class Prodecer {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Value("${queues.name}")
    private String QUEUES_NAME ;

    /**
     * contentType
     * @param content   内容
     * @param contentType  类型  text/plain / application/json
     */
    public void send(String content , String contentType ){

        Message message = MessageBuilder.withBody(content.getBytes())
                .setContentType(contentType)
                .setMessageId(UUID.randomUUID()+"")
                .setContentEncoding("UTF-8").build();

        this.amqpTemplate.convertAndSend("topicExchange","topic.messages","我是发送消息的内容! ");

        this.amqpTemplate.convertAndSend(QUEUES_NAME, message);
    }
}
